package com.caipos.actor.ruleChain;


import com.caipos.actor.ActorSystemContext;
import com.caipos.actor.common.actors.KbActor;
import com.caipos.actor.common.actors.KbActorCtx;
import com.caipos.actor.common.actors.KbActorId;
import com.caipos.actor.common.actors.KbEntityActorId;
import com.caipos.actor.common.data.id.RuleChainId;
import com.caipos.actor.common.data.id.TenantId;
import com.caipos.actor.common.data.rule.RuleChain;
import com.caipos.actor.common.msg.KbActorMsg;
import com.caipos.actor.service.ContextBasedCreator;

import java.util.UUID;

public class RuleChainActor extends RuleEngineComponentActor<RuleChainId, RuleChainActorMessageProcessor> {

    private final RuleChain ruleChain;

    private RuleChainActor(ActorSystemContext systemContext, TenantId tenantId, RuleChain ruleChain) {
        super(systemContext, tenantId, new RuleChainId(ruleChain.getId()));
        this.ruleChain = ruleChain;
    }

    @Override
    protected RuleChainActorMessageProcessor createProcessor(KbActorCtx ctx) {
        return new RuleChainActorMessageProcessor(tenantId, ruleChain, systemContext,
                ctx.getParentRef(), ctx);
    }

    @Override
    protected long getErrorPersistFrequency() {
        return 0;
    }

    @Override
    protected boolean doProcess(KbActorMsg msg) {
        System.err.println("RuleChainActor doProcess……");
        return false;
    }


    public static class ActorCreator extends ContextBasedCreator {
        private static final long serialVersionUID = 1L;

        private final TenantId tenantId;
        private final RuleChain ruleChain;

        public ActorCreator(ActorSystemContext context, TenantId tenantId, RuleChain ruleChain) {
            super(context);
            this.tenantId = tenantId;
            this.ruleChain = ruleChain;
        }

        @Override
        public KbActorId createActorId() {
            return new KbEntityActorId(new RuleChainId(ruleChain.getId()));
        }

        @Override
        public KbActor createActor() {
            return new RuleChainActor(context, tenantId, ruleChain);
        }

    }


    @Override
    protected RuleChainId getRuleChainId() {
        return null;
    }

    @Override
    protected String getRuleChainName() {
        return ruleChain.getName();
    }


}
